package com.yzcs.tvapp.simple.activity

import android.content.Context
import com.cxy.common.request.ApiAddress
import com.fy.baselibrary.base.ViewHolder
import com.fy.baselibrary.rv.adapter.MultiCommonAdapter
import com.fy.baselibrary.rv.adapter.MultiTypeSupport
import com.fy.baselibrary.utils.imgload.ImgLoadUtils
import com.yzcs.tvapp.R
import jp.wasabeef.glide.transformations.BlurTransformation
import java.util.*

/**
 * description 推荐 视频列表适配器
 * Created by fangs on 2021/1/12 11:34.
 */
class VideoListAdapter(context: Context, datas: ArrayList<VideoBean>) :
    MultiCommonAdapter<VideoBean, ViewHolder>(context, datas, object : MultiTypeSupport<VideoBean> {
        val titleType = 121
        val contentType = 122
        override fun getLayoutId(itemType: Int): Int {
            return if (itemType == titleType) R.layout.recommend_video_item_title else R.layout.recommend_video_item_content
        }

        override fun getItemViewType(position: Int, videoBean: VideoBean): Int {
            return if (videoBean.type == ApiAddress.listTitleType) titleType else contentType
        }
    }) {

    private val option = ImgLoadUtils.getDefaultOption(R.drawable.img_default).transform(BlurTransformation(25))


    override fun convert(holder: ViewHolder, item: VideoBean, position: Int) {
        if (item.type == ApiAddress.listTitleType){
            holder.setText(R.id.txtTitle, item.type_name)
        } else {
            ImgLoadUtils.loadImage(item.cover, holder.getView(R.id.imgVideoCover), option)
            holder.setText(R.id.txtVideoName, item.title)

            holder.setText(R.id.txtDesc, item.episodes_info)
            holder.setVisibility(R.id.txtDesc, item.episodes_info.isNotEmpty())

            holder.setText(R.id.txtRate, item.rate)
            holder.setVisibility(R.id.txtRate, item.rate.isNotEmpty())
        }
    }

}